package com.library.web.controller.tool;

import com.library.common.core.domain.AjaxResult;
import com.library.common.utils.uuid.UUID;
import com.library.framework.config.CosConfig;
import com.library.framework.manager.CosUploadManager;
import com.library.service.IQrCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 生成二维码服务
 *
 * @author wanghongjie
 */
@RestController
@RequestMapping("/tool/qrCode")
public class QrCodeController {
    @Resource
    private IQrCodeService qrCodeService;
    @Autowired
    private CosConfig cosConfig;

    /**
     * 生成二维码
     *
     * @param content 二维码内容
     * @return
     */
    @GetMapping("create")
    public AjaxResult createQrCode(String content) {
        byte[] qrCode = qrCodeService.createQrCode(content);
        String uploadUrl = CosUploadManager.uploadFilePubReadPivWrite(qrCode, cosConfig, UUID.fastUUID().toString().concat(".png"));
        return AjaxResult.success("成功", uploadUrl);
    }

}
